<template>
  <div class="birthday-popupbox">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="cancel"
      @confirm="confirm"
    />
  </div>
</template>

<script>
import { updateProfile } from "@/api/axios";
import dayjs from "dayjs";
export default {
  name: "birthday-popupbox",
  data() {
    return {
      minDate: new Date(2000, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(),
    };
  },
  props: {
    birthday: {
      type: [Number, String],
      required: true,
    },
  },
  methods: {
    cancel() {
      // 退出
      this.$emit("close");
    },
    async confirm() {
      this.$toast.loading({
        message: "修改中...",
        forbidClick: true,
      });

      try {
        // 转换时间
        let time = dayjs(this.currentDate).format("YYYY-MM-DD");
        // 发送请求
        const { data: res } = await updateProfile({ birthday: time });
        this.$toast.success('修改成功！')
        this.$emit('close',time)
      } catch (err) {
        console.log(err);
        this.$toast.file("响应失败，请重试！");
      }
    },
  },
  created() {
    console.log(this.birthday);
  },
};
</script>

<style lang='less' scoped>
</style>